using MicroMsg.Manager;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class ShakePeopleItem : UserControl
	{
		public delegate void ListItemClick(object sender, object object_0);
		public static DependencyProperty ListItemProperty = DependencyProperty.Register("ItemObject", typeof(ShakePeople), typeof(ShakePeopleItem), new PropertyMetadata(null, new PropertyChangedCallback(ShakePeopleItem.OnItemPropertyChanged)));
		internal Button btnLayoutRoot;
		internal Grid LayoutItem;
		internal StackPanel panelNickName;
		internal EmojiText txtNickName;
		internal Image imgSex;
		internal TextBlock txtFriendTag;
		internal Image imgHead;
		internal Image imgVerifyTag;
		internal TextBlock txtDistance;
		internal EmojiText txtSignature;
		internal Grid LayoutShowMore;
		internal TextBlock txtShowMore;
		internal PerformanceProgressBar progressBar;
		private bool _contentLoaded;
		public event ShakePeopleItem.ListItemClick ItemClick;
		public ShakePeople ItemObject
		{
			get
			{
				return (ShakePeople)base.GetValue(ShakePeopleItem.ListItemProperty);
			}
			set
			{
				base.SetValue(ShakePeopleItem.ListItemProperty, value);
			}
		}
		public ShakePeopleItem()
		{
			this.InitializeComponent();
			base.SetValue(TiltEffect.IsTiltEnabledProperty, true);
			ShakePage.AllShakePeopleItems.Add(this);
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ShakePeopleItem.ListItemProperty)
			{
				(dependencyObject_0 as ShakePeopleItem).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				this.RefreshItem(dependencyPropertyChangedEventArgs_0.get_NewValue() as ShakePeople);
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
		}
		private void refreshVerifyTag(ShakePeople item)
		{
			if (item != null && item.nVerifyFlag != 0)
			{
				if (this.imgVerifyTag.get_Source() == null)
				{
					this.imgVerifyTag.set_Source(ToolFunction.GetImgFromContentSource("/Resource/Img/ContactList/VerifyTag.png"));
				}
				this.imgVerifyTag.set_Visibility(0);
				return;
			}
			this.imgVerifyTag.set_Visibility(1);
		}
		private void RefreshItem(ShakePeople item)
		{
			this.refreshVerifyTag(item);
			if (item == null)
			{
				return;
			}
			if (item == ShakePage.ShowMoreIdentify)
			{
				this.LayoutShowMore.set_Background(R.theme.SHAKE_SHOW_MORE_BK_BRUSH);
				this.txtShowMore.set_Visibility(0);
				this.progressBar.set_Visibility(1);
				this.progressBar.IsIndeterminate = false;
				this.LayoutItem.set_Visibility(1);
				this.LayoutShowMore.set_Visibility(0);
				return;
			}
			this.LayoutShowMore.set_Visibility(1);
			this.LayoutItem.set_Visibility(0);
			this.txtSignature.Text = item.strSignature;
			if (item.bHasImg)
			{
				BitmapImage cacheHeadImage = HeadImgMgr.getCacheHeadImage(item);
				if (cacheHeadImage != HeadImgMgr.defaultHeadImage)
				{
					this.imgHead.set_Source(cacheHeadImage);
				}
				else
				{
					this.imgHead.set_Source(HeadImgMgr.getHeadImage(item.strUserName, true));
				}
			}
			else
			{
				this.imgHead.set_Source(HeadImageMgr.defaultHeadImage);
			}
			double num;
			if (ContactMgr.isFamous(item.nVerifyFlag))
			{
				this.txtDistance.set_Visibility(1);
				num = 0.0;
			}
			else
			{
				this.txtDistance.set_Visibility(0);
				this.txtDistance.set_Text(item.strDistance);
				num = this.txtDistance.get_ActualWidth();
			}
			Contact contact = StorageMgr.contact.method_0(item.strUserName);
			if (contact != null && ContactMgr.isContact(contact))
			{
				this.txtFriendTag.set_Visibility(0);
				this.txtNickName.set_MaxWidth(this.panelNickName.get_Width() - this.txtFriendTag.get_ActualWidth() - num - 40.0);
			}
			else
			{
				this.txtNickName.set_MaxWidth(this.panelNickName.get_Width() - num - 40.0);
				this.txtFriendTag.set_Visibility(1);
			}
			this.txtNickName.Text = item.strNickName;
			if (ShakePage.NewContactNames.Contains(item.strUserName))
			{
				this.txtNickName.Foreground = R.theme.SHAKE_HIGH_LIGHT_NAME_BRUSH;
				this.txtDistance.set_Foreground(R.theme.SHAKE_HIGH_LIGHT_OTHER_BRUSH);
				this.txtSignature.Foreground = R.theme.SHAKE_HIGH_LIGHT_OTHER_BRUSH;
			}
			else
			{
				this.txtNickName.Foreground = R.theme.LISTA_NAME_WORD_BRUSH;
				this.txtDistance.set_Foreground(R.theme.LISTA_TAG_WORD_BRUSH);
				this.txtSignature.Foreground = R.theme.LISTA_SIGNATURE_WORD_BRUSH;
			}
			if (item.nVerifyFlag != 0)
			{
				this.imgSex.set_Visibility(1);
				return;
			}
			if (1 == item.nSex)
			{
				this.imgSex.set_Source(ImageCacheMgr.loadFromRes(MMTheme.GetInstance().sexIcon_man));
				this.imgSex.set_Visibility(0);
				return;
			}
			if (2 == item.nSex)
			{
				this.imgSex.set_Source(ImageCacheMgr.loadFromRes(MMTheme.GetInstance().sexIcon_woman));
				this.imgSex.set_Visibility(0);
				return;
			}
			this.imgSex.set_Visibility(1);
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
			if (this.ItemClick != null)
			{
				this.ItemClick(this, this.ItemObject);
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Shake/UI/ShakePeopleItem.xaml", 2));
			this.btnLayoutRoot = (Button)base.FindName("btnLayoutRoot");
			this.LayoutItem = (Grid)base.FindName("LayoutItem");
			this.panelNickName = (StackPanel)base.FindName("panelNickName");
			this.txtNickName = (EmojiText)base.FindName("txtNickName");
			this.imgSex = (Image)base.FindName("imgSex");
			this.txtFriendTag = (TextBlock)base.FindName("txtFriendTag");
			this.imgHead = (Image)base.FindName("imgHead");
			this.imgVerifyTag = (Image)base.FindName("imgVerifyTag");
			this.txtDistance = (TextBlock)base.FindName("txtDistance");
			this.txtSignature = (EmojiText)base.FindName("txtSignature");
			this.LayoutShowMore = (Grid)base.FindName("LayoutShowMore");
			this.txtShowMore = (TextBlock)base.FindName("txtShowMore");
			this.progressBar = (PerformanceProgressBar)base.FindName("progressBar");
		}
	}
}
